<template>
  <div class="table_layout ">
    <div class="table_title" flex="main:justify cross:center">
      <div flex>
        <p>创建人：{{ tableData.creator || '--' }}</p>
        <p style="margin-left:20px">创建时间：{{ tableData.createTime || '--' }}</p>
      </div>
      <div>
        <template v-if="!patternIsEdit">
          <el-button class="margin_left_10" type="primary" plain size="mini" @click="showShare = true">分享</el-button>
          <el-button class="margin_left_10" size="mini">打印</el-button>
          <!-- <el-button class="margin_left_10" v-if="$store.state.archives.flag !== 2" size="mini" type="warning" plain @click="patternIsEdit = true">编辑</el-button> -->
        </template>
        <template v-else>
          <el-button class="margin_left_10" size="mini" plain type="success" :loading="loading" @click="handleSave">保存</el-button>
          <el-button class="margin_left_10" size="mini" plain type="danger" @click="handleGetData">取消</el-button>
        </template>
      </div>
    </div>
    <div class="table_containter">
      <div class="container_title">
        <!-- <p>{{ $store.state.user.departmentName }}</p> -->
        <h1>{{ $store.state.user.departmentName }}火灾调查文件</h1>
      </div>
      <table border="1" cellspacing="0" cellpadding="0" class="table_content">
        <tr>
          <td colspan="5">基本信息</td>
        </tr>
        <tr>
          <td>档案编号</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.no }}</td>
        </tr>
        <tr>
          <td>起火对象</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.fireObject }}</td>
        </tr>
        <tr>
          <td>起火地址</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.address }}</td>
        </tr>
        <tr>
          <td>起火天气</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.weather }}</td>
        </tr>
        <tr>
          <td colspan="5">出警信息</td>
        </tr>
        <tr>
          <td>报警时间</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.alarmTime }}</td>
        </tr>
        <tr>
          <td>调查时间</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.goTime }}</td>
        </tr>
        <tr>
          <td>承办单位</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.contractors }}</td>
        </tr>
        <tr>
          <td>火调人员</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.undertaker }}</td>
        </tr>
        <tr>
          <td>出警车辆</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.carInfo }}</td>
        </tr>
        <tr>
          <td>出警人数</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.peopleInfo }}</td>
        </tr>
        <tr>
          <td colspan="5">调查原因</td>
        </tr>
        <tr>
          <td>案件状态</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ [,'调查中','归档'][tableData.flag] }}</td>
        </tr>
        <tr>
          <td>伤亡情况</td>
          <td colspan="4" class="text_align_left padding_left_10">{{ tableData.casualties }}</td>
        </tr>
        <tr>
          <td rowspan="2">简单描述</td>
          <td rowspan="2" colspan="4" class="text_align_left padding_left_10">{{ tableData.details }}</td>
        </tr>
      </table>
    </div>
    <!-- <transition name="el-zoom-in-center">
      <div v-show="patternIsEdit" class="table_shade" />
    </transition> -->

    <shareComponent v-model="showShare" />
  </div>

</template>

<script>
// import { parseTime } from '@/utils/time'
// import { requestSave, requestGetById } from '@/api/home'
import shareComponent from './share'
export default {
  components: { shareComponent },
  data() {
    return {
      showShare: false,
      patternIsEdit: false,
      loading: false,
      url: '/archives',
      tableData: {}
    }
  },
  created() {
    this.handleGetData()
  },
  methods: {
    handleSave() {
      const formData = JSON.parse(JSON.stringify(this.tableData))
      formData.archivesId = this.$route.query.archivesId
      formData.alarmTime = `${formData.alarmTimeDate} ${formData.alarmTimeTime}:00`
      formData.title = '火灾调查登记表' + formData.name
      requestSave(formData, this.url).then(res => {
        this.$message.success('操作成功')
        this.$router.replace({ path: this.$route.path, query: { itemId: res.data, ...this.$route.query, isEdit: false }})
        this.handleGetData()
      })
    },
    handleGetData(come) {
      const itemId = this.$route.query.itemId
      this.patternIsEdit = come ? false : JSON.parse(this.$route.query.isEdit || 'false')
      if (!itemId) return
      requestGetById({ id: itemId }, this.url).then(res => {
        this.tableData = res.data
        console.log(res.data)
      })
    }

  }
}
</script>

